<?php
	abstract class AbstractPaymentHandler
	{
		protected $fieldProperties = array();
		
		protected $fieldValues = array();
		const ACTIVE = 1;
		const INACTIVE = 0;
		/**
		 * Redirect or perform any function required for begining payment process
		 * once payment handler is selected for payment.
		 */
		abstract function process(AppController $controller,$orderId);
		final function getFieldProperties()
		{
			$fieldProperties = array();
			$fieldProperties['title'] = array("type"=>"text",'default'=>Inflector::humanize($this->name),'validate'=>VALID_NOT_EMPTY);
			$fieldProperties = am($fieldProperties,$this->fieldProperties);
			$fieldProperties['status'] = array("type"=>"select",'options'=>array(self::ACTIVE =>__("Enabled"),self::INACTIVE=>__("Disabled")),'default'=>self::INACTIVE);
			$fieldProperties['allow_subscription'] = array("type"=>"select",'label'=>__("Use for subscription"),'options'=>array(__("No"),__("Yes")),'default'=>0);
			$fieldProperties['image_name'] = array("type"=>"text",'label'=>"Payment gateway button image name",'default'=>low($this->name).".png",'tooltip'=>__("Upload image with this name in /app/plugins/paid_listings/vendors/img folder using FTP client."));
			return $fieldProperties;
		}
		//abstract function getProcesingUrl();
		
		function setFieldPropetiesValue($values)
		{
			$this->fieldValues = $values;
		}
		
		function getFieldValue($field)
		{
			$value = false;
			$fieldProperties = $this->getFieldProperties();
			if(isset($this->fieldValues[$field]))
			{
				$value = $this->fieldValues[$field];
			}else if(isset($fieldProperties[$field]['default']))
			{
				$value = $fieldProperties[$field]['default'];
			}
			return $value;
		}
		
		function init()
		{
			parent::init();
		}
		
		function isEnabled()
		{
			return $this->getFieldValue('status') == self::ACTIVE;
		}
		
		function useForSubscription()
		{
			return $this->getFieldValue('allow_subscription') == 1;
		}
	}
?>